From c13d1cf9de22eca4a5e0517a3612902505ddba9a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 27 Aug 2014 08:01:26 -0700 Subject: [PATCH] Fix cargo-run rebasings and tests Closes #443 --- src/cargo/ops/cargo_run.rs | 17 +++++++++++------ tests/test_cargo_bench.rs | 1 + tests/test_cargo_cross_compile.rs | 24 +++--------------------- tests/test_cargo_run.rs | 2 +- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index 100918658..16fa41b1a 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -11,8 +11,9 @@ pub fn run(manifest_path: &Path, let mut src = try!(PathSource::for_path(&manifest_path.dir_path())); try!(src.update()); let root = try!(src.get_root_package()); + let env = options.env; let mut bins = root.get_manifest().get_targets().iter().filter(|a| { - a.is_bin() && a.get_profile().is_compile() + a.is_bin() && a.get_profile().get_env() == env }); let bin = try!(bins.next().require(|| { human("a bin target must be available for `cargo run`") @@ -24,11 +25,15 @@ pub fn run(manifest_path: &Path, } let compile = try!(ops::compile(manifest_path, options)); - let mut exe = manifest_path.dir_path().join("target"); - if options.env == "release" { - exe = exe.join("release"); - } - let exe = exe.join(bin.get_name()); + let dst = manifest_path.dir_path().join("target"); + let dst = match options.target { + Some(target) => dst.join(target), + None => dst, + }; + let exe = match bin.get_profile().get_dest() { + Some(s) => dst.join(s).join(bin.get_name()), + None => dst.join(bin.get_name()), + }; let exe = match exe.path_relative_from(&os::getcwd()) { Some(path) => path, None => exe, diff --git a/tests/test_cargo_bench.rs b/tests/test_cargo_bench.rs index 8e11ef803..acbd23ab9 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/test_cargo_bench.rs @@ -658,6 +658,7 @@ test!(bin_there_for_integration { output); }) +#[cfg(not(windows))] // FIXME(#456) test!(bench_dylib { let p = project("foo") .file("Cargo.toml", r#" diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 2d37a8084..7e65190d1 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -438,31 +438,13 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured test!(simple_cargo_run { if disabled() { return } - let target = alternate(); - - let build = project("builder") - .file("Cargo.toml", r#" - [project] - name = "foo" - version = "0.5.0" - authors = ["wycats@example.com"] - "#) - .file("src/main.rs", format!(r#" - fn main() {{ - assert_eq!(std::os::getenv("TARGET").unwrap().as_slice(), "{}"); - }} - "#, target).as_slice()); - assert_that(build.cargo_process("cargo-run").arg("--target").arg(target), - execs().with_status(0)); - let p = project("foo") - .file("Cargo.toml", format!(r#" + .file("Cargo.toml", r#" [package] name = "foo" version = "0.0.0" authors = [] - build = '{}' - "#, build.bin("foo").display())) + "#) .file("src/main.rs", r#" use std::os; fn main() { @@ -471,6 +453,6 @@ test!(simple_cargo_run { "#); let target = alternate(); - assert_that(p.cargo_process("cargo-run").arg("--target").arg(target), + assert_that(p.cargo_process("run").arg("--target").arg(target), execs().with_status(0)); }) diff --git a/tests/test_cargo_run.rs b/tests/test_cargo_run.rs index 9b967432a..61490b865 100644 --- a/tests/test_cargo_run.rs +++ b/tests/test_cargo_run.rs @@ -144,7 +144,7 @@ test!(release_works { fn main() { if !cfg!(ndebug) { fail!() } } "#); - assert_that(p.cargo_process("cargo-run").arg("--release"), + assert_that(p.cargo_process("run").arg("--release"), execs().with_status(0).with_stdout(format!("\ {compiling} foo v0.0.1 ({dir}) {running} `target{sep}release{sep}foo` -- 2.30.2